export class PhysicsEngine {
  constructor() {
    this.gravity = 0.5;
  }

  update(entity) {
    if (!entity) return;  // 防御性编程

    // 只在跳跃时应用重力
    if (entity.isJumping !== undefined && entity.isJumping) {
      entity.velocityY += this.gravity;
      entity.y += entity.velocityY;
    }
  }

  checkCollision(entity, obstacle) {
    if (!entity || !obstacle) return false;

    return (
      entity.x < obstacle.x + obstacle.width &&
      entity.x + entity.width > obstacle.x &&
      entity.y < obstacle.y + obstacle.height &&
      entity.y + entity.height > obstacle.y
    );
  }
}
// 在文件底部添加
export default PhysicsEngine
